package com.eos.control.action.emp;

import java.util.ArrayList;
import java.util.List;

import com.eos.common.tool.DataCacheUtil;
import com.eos.common.tool.PageModelUtil;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysUser;
import com.hf.utils.StringUtil;

public class LookUpEmpListAction extends AbstractBaseAction {
	private static final long serialVersionUID = -7940014987895440787L;
	private String userName;
	private String status;
	private Integer pageNum;
	private Integer numPerPage;
	private List<SysUser> userList;
	private Integer totalCount;
	
	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Integer getPageNum() {
		return pageNum;
	}

	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	public Integer getNumPerPage() {
		return numPerPage;
	}

	public void setNumPerPage(Integer numPerPage) {
		this.numPerPage = numPerPage;
	}

	public String getUserName() {
		return userName;
	}

	public String getStatus() {
		return status;
	}

	public List<SysUser> getUserList() {
		return userList;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String execute() {
		try {
			if(null == pageNum || pageNum.intValue() == 0) pageNum = 1;
			if(null == numPerPage || numPerPage.intValue() == 0) numPerPage = PAGE_SIZE;
			if(StringUtil.isEmpty(status)) status = "2";
			List<SysUser> ulist = DataCacheUtil.getAllSysUser();
			List<SysUser> rtnList = new ArrayList<SysUser>();
			if(!StringUtil.isEmpty(userName) && ulist != null){
				for(SysUser user : ulist){
					if(user.getUserName().indexOf(userName) >=0){
						rtnList.add(user);
					}
				}
			}else{
				rtnList = ulist;
			}
			List<SysUser> rtnList2 = new ArrayList<SysUser>();
			if(!"2".equals(status)){
				for(SysUser su : rtnList){
					if(su.getStatus().equals(status)){
						rtnList2.add(su);
					}
				}
			}else{
				rtnList2 = rtnList;
			}
			PageModelUtil pdm = new PageModelUtil(rtnList2, numPerPage);
			userList = (List<SysUser>) pdm.getCurrentPage(pageNum);
			totalCount = null != rtnList2 ? rtnList2.size() : 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
}
